package com.shijie.controller.erp;

import com.shijie.service.DictsService;
import com.shijie.domain.entity.Dicts;
import com.shijie.domain.enums.EnumInterface;
import com.shijie.core.Result;
import com.shijie.core.ResultGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.web.bind.annotation.*;

import tk.mybatis.mapper.entity.Condition;

import javax.annotation.Resource;
import javax.net.ssl.SSLEngineResult.Status;

import java.util.List;

/*
 *  @author: smart boy
 *  @date: 2018-08-06
 */
@RestController
@RequestMapping("/erp/dicts")
public class DictsController {

    @Resource
	private DictsService dictsService;

	@GetMapping
    public Result list(@RequestParam(required=false) String dictType) {
        Condition condition = new Condition(Dicts.class);
        condition.createCriteria().andEqualTo("dictType", dictType).andEqualTo("status", EnumInterface.Status.VALID.ordinal());
        condition.orderBy("sorts").asc();
        List<Dicts> list = dictsService.selectByCondition(condition);
        return ResultGenerator.success(list);
	}

	@GetMapping("byTypes")
	public Result getDictionarysByType(@RequestParam String dictType){
		Condition condition = new Condition(Dicts.class);
		return ResultGenerator.success(dictsService.selectByCondition(condition));
	}
}

